from wordcloud import WordCloud
import matplotlib.pyplot as plt

# 正面数据
positive_data = {
    "问题": 0.05,
    "声音": 0.028,
    "流量": 0.025,
    "时间": 0.025,
    "耳机": 0.024,
    "脸": 0.024,
    "屏幕": 0.017,
    "牙": 0.015,
    "网": 0.013,
    "时候": 0.026,
    "钱": 0.024,
    "视频": 0.022,
    "用户": 0.02,
    "人": 0.017,
    "店": 0.015,
    "电话": 0.013,
    "语音": 0.013,
    "软件": 0.012,
    "卡": 0.049,
    "游戏": 0.037,
    "电池": 0.028,
    "售后": 0.024,
    "内存": 0.02,
    "小时": 0.02,
    "信息": 0.018,
    "电": 0.017,
    "像素": 0.017,
    "网络": 0.016,
    "手机": 0.261,
}

# 负面数据
negative_data = {
    "手机": 0.207,
    "视频": 0.031,
    "耳机": 0.025,
    "无法": 0.018,
    "网络": 0.017,
    "电话": 0.015,
    "售后": 0.013,
    "小时": 0.013,
    "时": 0.011,
    "卡": 0.08,
    "声音": 0.039,
    "脸": 0.028,
    "时间": 0.028,
    "有点": 0.021,
    "妈": 0.021,
    "店里": 0.018,
    "意思": 0.016,
    "流量": 0.015,
    "原因": 0.014,
    "问题": 0.064,
    "游戏": 0.047,
    "时候": 0.046,
    "垃圾": 0.031,
    "软件": 0.029,
    "人": 0.028,
    "密码": 0.024,
    "用户": 0.02,
    "情况": 0.016,
    "码": 0.015,
}

# 生成正面数据词云
positive_wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='my_font.TTF').generate_from_frequencies(positive_data)

# 生成负面数据词云
negative_wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='my_font.TTF').generate_from_frequencies(negative_data)
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定使用的中文字体，这里以宋体（SimHei）为例
# 绘制正面数据词云
plt.figure(figsize=(10, 5))
plt.imshow(positive_wordcloud, interpolation='bilinear')
plt.axis('off')
plt.title('正面情感评论数据词云')

# 绘制负面数据词云
plt.figure(figsize=(10, 5))
plt.imshow(negative_wordcloud, interpolation='bilinear')
plt.axis('off')
plt.title('负面情感评论数据词云')
plt.show()
